from page.register_page import RegisterPage
import time
from util.get_code import GetCode

class RegisterHandle:

    def __init__(self,driver):
        self.driver = driver
        self.register_p = RegisterPage(self.driver)


    def send_email(self,email):
        element = self.register_p.get_email_element()
        self.register_p.get_email_element().send_keys(email)

    def send_username(self,username):
        self.register_p.get_username_element().send_keys(username)


    def send_password(self,password):
        self.register_p.get_password_element().send_keys(password)

    def send_code(self,code):
        # get_code_text = GetCode(self.driver)
        # code = get_code_text.code_online(file_name)
        self.register_p.get_code_element().send_keys(code)


    def click_register_button(self):
        self.register_p.get_register_button_element().click()

    def get_text(self,info,text_info):

        text = ''
        try:
            if info == 'email_error':
                text= self.register_p.get_emailerror_element().text
            elif info == 'user_name_error':
                text= self.register_p.get_usererror_element().text
            elif info == 'password_error':
                text = self.register_p.get_passworderror_element().text
            elif info == 'code_error':
                text =self.register_p.get_codeerror_element().text
        except:
            text = None

        return text


    def get_register_tesxt(self):
        return self.register_p.get_register_button_element().text